<?php

namespace app\admin\command;

use addons\shopro\service\commission\Agent as AgentService;
use app\admin\model\shopro\commission\Agent;
use app\admin\model\shopro\user\WalletLog;
use app\admin\model\User;
use app\common\model\MoneyLog;
use app\common\model\ScoreLog;
use app\common\model\TokensLog;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\Db;

class RunUserLevel extends Command
{
    protected function configure()
    {
        $this->setName("run-user-level");
    }

    protected function execute(Input $input, Output $output)
    {

        Db::name('user')
            ->chunk(100, function ($list) use ($output) {
                foreach ($list as $item) {
                    $output->write("当前ID:" . $item['id']);
                    $agent = new AgentService($item['id']);
                    if ($agent->user) {
                        Db::transaction(function () use ($agent) {
                            $agent->runAgentUpgradePlan();
                        });
                    }
                }
            });
        $output->write("跑完了");
    }
}
